package com.bdjk.bdmw.InfoGath.communication.protocol.littleNurse;

import com.bdjk.bdmw.InfoGath.business.nurse.vo.NursePositionVO;
import com.bdjk.bdmw.InfoGath.communication.protocol.BaseProtocol;
import java.text.SimpleDateFormat;
import java.util.Date;

public class NurseMultiLBSProtocol
  extends BaseProtocol<NursePositionVO>
{
  public NurseMultiLBSProtocol()
  {
    this.isResponse = true;
    this.isSave = true;
  }
  
  public String encodeMessage(NursePositionVO vo)
  {
    StringBuffer str = new StringBuffer("[");
    str.append(vo.getProVersion() + ",");
    str.append(vo.getMesId() + ",");
    str.append(vo.getEncryptType() + ",");
    str.append(vo.getValidatCode() + ",");
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    str.append(df.format(Long.valueOf(System.currentTimeMillis())) + ",");
    str.append(vo.getTerIdent() + ",");
    str.append(vo.getMesType().replace('T', 'S') + "]");
    
    str.append("[");
    str.append(vo.getProVersion() + ",");
    str.append(vo.getMesId() + ",");
    str.append(vo.getEncryptType() + ",");
    str.append(vo.getValidatCode() + ",");
    str.append(df.format(Long.valueOf(System.currentTimeMillis())) + ",");
    str.append(vo.getTerIdent() + ",");
    
    str.append("S13]");
    return str.toString();
  }
  
  public NursePositionVO decodeMessage(String message)
  {
    NursePositionVO vo = new NursePositionVO();
    String[] params = message.split(",");
    vo.setProVersion(params[0]);
    vo.setMesId(params[1]);
    vo.setEncryptType(params[2]);
    vo.setValidatCode(params[3]);
    vo.setSendTime(params[4]);
    vo.setTerType(params[5]);
    vo.setTerIdent(params[6]);
    vo.setTimeZone(params[7]);
    vo.setMesType(params[8]);
    vo.setElectricity(params[9]);
    vo.setBaseInfo(params[10]);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Date date = new Date(Long.valueOf(params[11]).longValue());
    vo.setCollectMills(format.format(date));
    this.terIdent = vo.getTerIdent();
    return vo;
  }
}
